package com.xuxin.baby.adapter;

import android.widget.ImageView;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xuxin.baby.R;
import com.xuxin.baby.database.HistoryBean;
import com.xuxin.baby.glide.GlideApp;
import com.xuxin.baby.network.Retrofit;

import org.jetbrains.annotations.NotNull;

/**
 * Created by xu_xin
 * Created on 2020.08.28 0028
 * 历史足迹
 */
public class HistoryAdapter extends BaseMultiItemQuickAdapter<HistoryBean, BaseViewHolder> {
    RequestOptions options = new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10));

    public HistoryAdapter() {
        addItemType(0, R.layout.item_video);
        addItemType(1, R.layout.item_reader);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, HistoryBean dataBean) {
        switch (holder.getItemViewType()) {
            case 0:
                holder.setText(R.id.item_video_name, dataBean.getTitle());
                holder.setText(R.id.item_video_content, dataBean.getContent());
                /**
                 * 加载图片
                 */
                ImageView item_video_image = holder.getView(R.id.item_video_image);
                String HistoryVideoImage = Retrofit.image_url + dataBean.getImage();
                LogUtils.e("历史足迹_image = " + HistoryVideoImage);
                GlideApp.with(getContext()).load(HistoryVideoImage).placeholder(R.mipmap.img_placeholder260).apply(options).into(item_video_image);
                break;
            case 1:
                holder.setText(R.id.item_reader_name, dataBean.getTitle());
                holder.setText(R.id.item_reader_content, dataBean.getContent());
                /**
                 * 加载图片
                 */
                ImageView item_reader_image = holder.getView(R.id.item_reader_image);
                String HistoryReaderImage = Retrofit.image_url + dataBean.getImage();
                LogUtils.e("历史足迹_image = " + HistoryReaderImage);
                GlideApp.with(getContext()).load(HistoryReaderImage).placeholder(R.mipmap.img_placeholder260).apply(options).into(item_reader_image);
                break;
        }
    }
}